<template>
  <div ref="chartRef" style="width: 600px; height: 400px;"></div>
</template>

<script setup>
import { onMounted, onBeforeUnmount, ref } from 'vue';
import { getCurrentInstance } from 'vue';

const instance = getCurrentInstance();
const chartRef = ref(null);
let chart = null;

onMounted(() => {
  chart = instance.appContext.config.globalProperties.$echarts.init(chartRef.value);
  const option = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [120, 200, 150, 80, 70, 110, 130],
        type: 'bar'
      }
    ]
  };
  chart.setOption(option);
});

onBeforeUnmount(() => {
  if (chart) {
    chart.dispose();
  }
});
</script>
